package hot150;

import java.util.Arrays;
import java.util.HashMap;
import java.util.TreeMap;

// https://leetcode.cn/problems/h-index/description/?envType=study-plan-v2&envId=top-interview-150
public class q11 {

    public int hIndex(int[] citations) {
        return method1(citations, citations.length);
    }

    /**
     * 排序
     * 1 ms
     * 复杂度O(nlogn)
     */
    public int method1(int[] citations, int n) {
        Arrays.sort(citations);
        for (int i = 0 ; i < n ; i++) {
            if (citations[i] >= n - i) {
                return n - i;
            }
        }
        return 0;
    }


    public static void main(String[] args) {
        System.out.println(new q11().hIndex(new int[]{1,3,1}));
    }
}
